<template>
  <el-dialog
    v-model="visible"
    title="违规管理"
    :close-on-click-modal="false"
    width="35%"
    class="component-offline-event-handle"
  >
    <!-- native modifier has been removed, please confirm whether the function has been affected  -->
    <!-- native modifier has been removed, please confirm whether the function has been affected  -->
    <el-form
      ref="dataFormRef"
      :model="dataForm"
      :rules="dataRule"
      label-width="80px"
      @submit.prevent
      @keyup.enter="onSubmit()"
    >
      <el-form-item
        label="处理人"
        prop="handler"
      >
        <el-input
          v-model="dataForm.handler"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item
        label="处理状态"
        prop="status"
      >
        <!-- 1平台进行下线 2 重新申请，等待审核 3.审核通过 4 审核未通过 -->
        <div v-if="dataForm.status === 1">
          平台下线
        </div>
        <div v-else-if="dataForm.status === 2">
          等待审核
        </div>
        <div v-else-if="dataForm.status === 3">
          审核通过
        </div>
        <div v-else-if="dataForm.status === 4">
          审核不通过
        </div>
        <div v-else>
          其他
        </div>
      </el-form-item>
      <el-form-item
        label="下线原因"
        prop="offlineReason"
      >
        <el-input
          v-model="dataForm.offlineReason"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 10}"
          maxlength="200"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item
        label="下线时间"
        prop="createTime"
      >
        <el-input
          v-model="dataForm.createTime"
          :disabled="true"
        />
      </el-form-item>
      <el-form-item
        v-if="dataForm.status === 1 || dataForm.status === 4"
        label="申请理由"
        prop="reapplyReason"
      >
        <el-input
          v-model="reapplyReason"
          type="textarea"
          :autosize="{ minRows: 2, maxRows: 10}"
          maxlength="200"
          :disabled="!(dataForm.status === 1 || dataForm.status === 4)"
        />
      </el-form-item>
    </el-form>
    <el-divider />
    <div>
      <div style="margin-bottom:10px">
        <strong>申请日志</strong>
      </div>
      <div
        v-for="item in dataForm.offlineHandleEventItemList"
        :key="item.eventItemId"
      >
        <el-row

          justify="space-around"
        >
          <el-col :span="3">
            <strong>申请时间：</strong>
          </el-col>
          <el-col :span="24">
            <span class="content-color">{{ item.createTime }}</span>
          </el-col>
        </el-row>
        <el-row

          justify="space-around"
        >
          <el-col :span="3">
            <strong>申请理由：</strong>
          </el-col>
          <el-col :span="24">
            <div> <span class="content-color">{{ item.reapplyReason }}</span></div>
          </el-col>
        </el-row>
        <el-row
          v-if="item.auditTime"

          justify="space-around"
        >
          <el-col :span="3">
            <strong>审核时间：</strong>
          </el-col>
          <el-col :span="24">
            <div> <span class="content-color">{{ item.auditTime }}</span></div>
          </el-col>
        </el-row>
        <el-row
          v-if="item.refuseReason"

          justify="space-around"
        >
          <el-col :span="3">
            <strong>拒绝原因：</strong>
          </el-col>
          <el-col :span="24">
            <div> <span class="content-color">{{ item.refuseReason }}</span></div>
          </el-col>
        </el-row>
        <div style="width:50%">
          <el-divider />
        </div>
      </div>
    </div>

    <template #footer>
      <span

        class="dialog-footer"
      >
        <div
          class="default-btn"
          @click="visible = false"
        >取消</div>
        <div
          class="default-btn primary-btn"
          :disabled="dataForm.status !== 1 && dataForm.status !== 4"
          @click="onSubmit()"
        >提交申请</div>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ElMessage, ElMessageBox } from 'element-plus'
const emit = defineEmits(['refreshDataList', 'refreshDataList'])
const props = defineProps({
  selectUrl: {
    default: '',
    type: String
  },
  applyUrl: {
    default: '',
    type: String
  }
})

const visible = ref(false)
const dataForm = ref({
  eventId: null,
  handleType: null,
  handleId: null,
  shopId: null,
  handlerId: null,
  status: null,
  offlineReason: null
})
const reapplyReason = ref('')
let id = 0
const dataRule = {
}

const init = (_id) => {
  id = _id || 0
  visible.value = true
  nextTick(() => {
    // $refs['dataForm'].resetFields()
    if (id) {
      http({
        url: http.adornUrl(props.selectUrl + '/' + _id),
        method: 'get',
        params: http.adornParams()
      }).then(({ data }) => {
        if (!data) {
          ElMessage({
            message: '商品不在审核状态，请刷新后重试',
            type: 'error',
            duration: 1500,
            onClose: () => {
              reapplyReason.value = ''
              visible.value = false
              emit('refreshDataList')
            }
          })
        }
        dataForm.value = data
      })
    }
  })
}
defineExpose({ init })
// 表单提交
const onSubmit = () => {
  if (!reapplyReason.value) {
    ElMessage.error('申请理由不能为空')
    return
  }
  ElMessageBox.confirm('确定提交申请吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消'
  }).then(() => {
    http({
      url: http.adornUrl(props.applyUrl),
      method: 'post',
      data: http.adornData({
        eventId: dataForm.value.eventId,
        handleId: id,
        reapplyReason: reapplyReason.value
      })
    }).then(() => {
      ElMessage({
        message: $t('remindPop.success'),
        type: 'success',
        duration: 1500,
        onClose: () => {
          reapplyReason.value = ''
          visible.value = false
          emit('refreshDataList')
        }
      })
    })
  })
}

</script>

<style lang="scss" scoped>
.content-color {
  color: #4395ff;
  word-break: break-word;
}
</style>
